//
//  AppMacro.h
//  iOSCodeProject
//
//  Created by Fox on 14-7-17.
//  Copyright (c) 2014年 翔傲信息科技（上海）有限公司. All rights reserved.
//

/**
 *  项目内公共常用宏定义
 */

#ifndef iOSCodeProject_AppMacro_h
#define iOSCodeProject_AppMacro_h

#pragma mark - Format
/**
 *  生成字符串
 *
 *  @param ... 格式化参数
 *
 *  @return 得到的字符串
 */
#define str(...) [NSString stringWithFormat:__VA_ARGS__]

/**
 *  根据名字返回对应的图片
 */
#define img(name) [UIImage imageNamed:name]


#pragma mark - Block

/**
 *  弱引用对象
 *
 *  @param self 当前对象
 *
 *  @return 弱应用对象
 */
#define WEAKSELF typeof(self) __weak weakSelf = self;

/**
 *  强引用对象
 *
 *  @param self 当前对象
 *
 *  @return 强引用对象
 */
#define STRONGSELF typeof(self) __strong strongSelf = self;

#pragma mark - Debug

#ifdef DEBUG

/**
 *  在Debug模式下，输出内容
 */
#define DLOG(...)   NSLog(__VA_ARGS__)

/**
 *  在Debug模式下，输出Point信息
 *
 *  @param p 点
 *
 *  @return 点的x和y
 */
#define DLOGPOINT(p)	NSLog(@"%f,%f", p.x, p.y);

/**
 *  在Debug模式下，输出Size信息
 *
 *  @param size 大小
 *
 *  @return 大小的width和height
 */
#define DLOGSIZE(size)	NSLog(@"%f,%f", size.width, size.height);

/**
 *  在Debug模式下，输出Fame信息
 *
 *  @param  p  位置信息
 *
 *  @return 位置的x、y、width和height
 */
#define DLOGRECT(p)	NSLog(@"%f,%f %f,%f", p.origin.x, p.origin.y, p.size.width, p.size.height);

#else

#define DLOG(...)
#define DLOGPOINT(p)
#define DLOGSIZE(p)
#define DLOGRECT(p)

#endif

#pragma mark - Tools methods
/**
 *  判断一个对象是否为空
 *
 *  @param thing 对象
 *
 *  @return 返回结果
 */
static inline BOOL ICIsObjectEmpty(id thing){
    return thing == nil ||
    ([thing isEqual:[NSNull null]]) ||
    ([thing respondsToSelector:@selector(length)] && [(NSData *)thing length] == 0) ||
    ([thing respondsToSelector:@selector(count)]  && [(NSArray *)thing count] == 0);
}

/**
 *  判断一个字符串是否为空
 *
 *  @param string 字符串
 *
 *  @return 返回结果
 */
static inline BOOL ICIsStringEmpty(NSString *string){
    
    if (string == nil) {
        return YES;
    }
    
    if (string.length == 0) {
        return YES;
    }
    
    if ([string isEqualToString:@"<null>"]) {
        return YES;
    }
    
    if ([string isEqualToString:@"(null)"]) {
        return YES;
    }
    
    return NO;
}

/**
 *  计算2个日期的时间间隔
 *
 *  @param firstDate  <#firstDate description#>
 *  @param secondDate <#secondDate description#>
 *
 *  @return <#return value description#>
 */
static inline NSInteger countTwoDays(NSDate *firstDate, NSDate *secondDate){
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat  = @"yyyy-MM-dd";
    NSString *firstDateStr = [formatter stringFromDate:firstDate];
    NSString *secondDateStr = [formatter stringFromDate:secondDate];
    
    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSUInteger unitFlags = NSMonthCalendarUnit | NSDayCalendarUnit;
    NSDateComponents *components = [gregorian components:unitFlags fromDate:[formatter dateFromString:firstDateStr] toDate:[formatter dateFromString:secondDateStr] options:0];
    NSInteger days = [components day];
    return days;
}

//程序全局委托
#ifndef ApplicationDelegate
#define ApplicationDelegate   ((AppDelegate*)[[UIApplication sharedApplication] delegate])
#endif

//安全释放
#ifndef RELEASE
#define RELEASE(x)         if(nil != (x)){ [(x) release]; (x) = nil;}
#endif

#pragma mark - iPhone5 adaptation
//是否为iPhone5
#ifndef iPhone5
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ?  \
CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#endif

//是否为iPhone4
#ifndef iPhone4
#define iPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ?  \
CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
#endif

//设备屏幕高度
#ifndef UIScreenHeight
#define UIScreenHeight   [UIScreen mainScreen].bounds.size.height
#endif

//设备屏幕宽度
#ifndef UIScreenWidth
#define UIScreenWidth    [UIScreen mainScreen].bounds.size.width
#endif

//是否为ios7
#ifndef IOS7
#define IOS7            ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0?YES:NO)
#endif

//如果为ios7，则返回20的冗余
#ifndef IOS7_PADDING
#define IOS7_PADDING    ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0?20:0)
#endif


//定义颜色
#define RGBACOLOR(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]
//区分真机和模拟器
//TARGET_OS_IPHONE  是否为真机
//TARGET_IPHONE_SIMULATOR  是否为模拟器
/*
if (TARGET_OS_IPHONE) {
    //真机
}else{
    //非真机
}
 */

//区分是否为ARC
#if __has_feature(objc_arc)
//compiling with ARC
#else
// compiling without ARC
#endif

#define MAIN_GREEN_COLOR RGBACOLOR(48, 207, 198, 1)
#define MAIN_RED_COLOR RGBACOLOR(228, 0, 29, 1)
#define TicketColor_10_yuan RGBACOLOR(185, 129, 238, 1)
#define TicketColor_20_yuan RGBACOLOR(246, 180, 92, 1)
#define TicketColor_30_yuan RGBACOLOR(240, 155, 160, 1)
#define TicketColor_OutOfDate RGBACOLOR(210, 210, 210, 1)
#define TicketImage_OutOfDate_left @"ticket_0_left"
#define TicketImage_OutOfDate_right @"ticket_0_right"
#define TicketImage_10_yuan_left @"ticket_1_left"
#define TicketImage_10_yuan_right @"ticket_1_right"
#define TicketImage_20_yuan_left @"ticket_2_left"
#define TicketImage_20_yuan_right @"ticket_2_right"
#define TicketImage_30_yuan_left @"ticket_3_left"
#define TicketImage_30_yuan_right @"ticket_3_right"

//=================================================
//  定义了订单的所以状态
//
//=================================================
#define  BOOKING_PAY_WAIT 1 // (1,"等待支付订金"),
#define BOOKING_CANCEL 2 // (2,"预约取消"),
#define BOOKING_FAILURE 3 // (3,"预约失败"),
#define BOOKING_TIMEOUT 4 // (4,"预约超时"),
#define BOOKING_SUCCESS 5 // (5,"预约成功"),
#define CHECKIN 6 // (6,"正在入库"),
#define REACHED 7 // (7,"车已入库"),
#define REFUND_WAIT 8 // (8,"等待退款"),
#define REFUND_FINISH 9 // (9,"退款完成"),
#define PARKING_FINISH 10 // (10,"已支付停车费");

/**
 *  判断 字符串 是否 是 NULL NSNULL
 *
 *  @param String <#String description#>
 *
 *  @return <#return value description#>
 */
static inline NSString* VALID_STRING(NSString *string){
    
    if([string isKindOfClass:[NSNull class]]){
        
        return @"";
    }else{
        
        return string;
    }
}

#endif
